﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace ChinaSoft.Web.Model_tb_MidSoft_Customer
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int CustomerId=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(CustomerId);
				}
			}
		}
			
	private void ShowInfo(int CustomerId)
	{
		ChinaSoft.BLL.BLL_tb_MidSoft_Customer bll=new ChinaSoft.BLL.BLL_tb_MidSoft_Customer();
		ChinaSoft.Model.Model_tb_MidSoft_Customer model=bll.GetModel(CustomerId);
		this.lblCustomerId.Text=model.CustomerId.ToString();
		this.txtCustomerName.Text=model.CustomerName;
		this.txtCustomerNumber.Text=model.CustomerNumber;
		this.txtContactName.Text=model.ContactName;
		this.txtContactType.Text=model.ContactType;
		this.txtContactTel.Text=model.ContactTel;
		this.txtContactAddress.Text=model.ContactAddress;
		this.txtContactMail.Text=model.ContactMail;
		this.txtCreateTime.Text=model.CreateTime.ToString();
		this.txtCreateUserId.Text=model.CreateUserId.ToString();

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtCustomerName.Text.Trim().Length==0)
			{
				strErr+="客户名称不能为空！\\n";	
			}
			if(this.txtCustomerNumber.Text.Trim().Length==0)
			{
				strErr+="客户编号不能为空！\\n";	
			}
			if(this.txtContactName.Text.Trim().Length==0)
			{
				strErr+="联系人不能为空！\\n";	
			}
			if(this.txtContactType.Text.Trim().Length==0)
			{
				strErr+="联系方式不能为空！\\n";	
			}
			if(this.txtContactTel.Text.Trim().Length==0)
			{
				strErr+="联系电话不能为空！\\n";	
			}
			if(this.txtContactAddress.Text.Trim().Length==0)
			{
				strErr+="联系地址不能为空！\\n";	
			}
			if(this.txtContactMail.Text.Trim().Length==0)
			{
				strErr+="联系邮箱不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtCreateTime.Text))
			{
				strErr+="创建时间格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtCreateUserId.Text))
			{
				strErr+="创建人ID格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int CustomerId=int.Parse(this.lblCustomerId.Text);
			string CustomerName=this.txtCustomerName.Text;
			string CustomerNumber=this.txtCustomerNumber.Text;
			string ContactName=this.txtContactName.Text;
			string ContactType=this.txtContactType.Text;
			string ContactTel=this.txtContactTel.Text;
			string ContactAddress=this.txtContactAddress.Text;
			string ContactMail=this.txtContactMail.Text;
			DateTime CreateTime=DateTime.Parse(this.txtCreateTime.Text);
			int CreateUserId=int.Parse(this.txtCreateUserId.Text);


			ChinaSoft.Model.Model_tb_MidSoft_Customer model=new ChinaSoft.Model.Model_tb_MidSoft_Customer();
			model.CustomerId=CustomerId;
			model.CustomerName=CustomerName;
			model.CustomerNumber=CustomerNumber;
			model.ContactName=ContactName;
			model.ContactType=ContactType;
			model.ContactTel=ContactTel;
			model.ContactAddress=ContactAddress;
			model.ContactMail=ContactMail;
			model.CreateTime=CreateTime;
			model.CreateUserId=CreateUserId;

			ChinaSoft.BLL.BLL_tb_MidSoft_Customer bll=new ChinaSoft.BLL.BLL_tb_MidSoft_Customer();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
